home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / libol / command.h < prev    next >
C/C++ Source or Header  |  2005-10-16  |  9KB  |  294 lines

  1. /***************************************************************************
  2.  *
  3.  * Copyright (c) 1998-1999 Niels M÷ller
  4.  * Copyright (c) 1999 BalaBit Computing
  5.  * 
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * $Id: command.h,v 1.1 1999/07/10 13:23:09 bazsi Exp $
  21.  *
  22.  ***************************************************************************/
  23.  
  24. #ifndef __COMMAND_H_INCLUDED
  25. #define __COMMAND_H_INCLUDED
  26.  
  27. #include "list.h"
  28. #include "io.h"
  29.  
  30. #include <stdarg.h>
  31.  
  32. #define CLASS_DECLARE
  33. #include "command.h.x"
  34. #undef CLASS_DECLARE
  35.  
  36. /* Continuation based command execution. A command can take one object
  37.  * as argument, and returns one object. */
  38.  
  39. /* CLASS:
  40.    (class
  41.      (name command_continuation)
  42.      (vars
  43.        (c method int "struct ol_object *result")))
  44. */
  45.  
  46. /* CLASS:
  47.    (class
  48.      (name command)
  49.      (vars
  50.        (call method int "struct ol_object *arg"
  51.                         "struct command_continuation *c")))
  52. */
  53.  
  54. /* CLASS:
  55.    (class
  56.      (name command_simple)
  57.      (super command)
  58.      (vars
  59.        ;; Like call, but returns the value immediately rather than
  60.        ;; using a continuation function
  61.        (call_simple method "struct ol_object *" "struct ol_object *")))
  62. */
  63.  
  64. #define COMMAND_CALL(f, a, c) \
  65.   ((f)->call((f), (struct ol_object *) (a), (c)))
  66. #define COMMAND_RETURN(r, v) \
  67.   ((r) ? ((r)->c((r), (struct ol_object *) (v))) : ST_OK | ST_GOON)
  68. #define COMMAND_SIMPLE(f, a) \
  69.   ((f)->call_simple((f), (struct ol_object *)(a)))
  70.  
  71. int do_call_simple_command(struct command *s,
  72.                struct ol_object *arg,
  73.                struct command_continuation *c);
  74.  
  75. #define STATIC_COMMAND_SIMPLE(f) \
  76. { { STATIC_HEADER, do_call_simple_command }, f}
  77.  
  78. struct command *make_parallell_progn(struct object_list *body);
  79. extern struct command_simple progn_command;
  80.  
  81. /* CLASS:
  82.    (class
  83.      (name command_frame)
  84.      (super command_continuation)
  85.      (vars
  86.        (up object command_continuation)))
  87. */
  88.  
  89. /* Commands that need to collect some arguments before actually doing
  90.  * anything. */
  91.  
  92. /* The collect_info_n classes keeps track about what to do whith the
  93.  * next argument. As long as we collect arguments without doing
  94.  * anything, the f field in collect_info_n will point to the
  95.  * constructor make_collect_state_n. */
  96. /* CLASS:
  97.    (class
  98.      (name collect_info_4)
  99.      (vars
  100.        (f method "struct ol_object *"
  101.                  "struct ol_object *" "struct ol_object *"
  102.          "struct ol_object *" "struct ol_object *")
  103.        ;; No next field
  104.        ))
  105. */
  106.  
  107. /* CLASS:
  108.    (class
  109.      (name collect_info_3)
  110.      (vars
  111.        (f method  "struct ol_object *"
  112.                   "struct ol_object *" "struct ol_object *"
  113.           "struct ol_object *")
  114.        (next object collect_info_4)))
  115. */
  116.  
  117. /* CLASS:
  118.    (class
  119.      (name collect_info_2)
  120.      (vars
  121.        (f method  "struct ol_object *"
  122.                   "struct ol_object *" "struct ol_object *")
  123.        (next object collect_info_3)))
  124. */
  125.  
  126. /* CLASS:
  127.    (class
  128.      (name collect_info_1)
  129.      (super command_simple)
  130.      (vars
  131.        (f method  "struct ol_object *"
  132.                   "struct ol_object *")
  133.        (next object collect_info_2)))
  134. */
  135.  
  136. struct ol_object *
  137. do_collect_1(struct command_simple *s, struct ol_object *a);
  138.  
  139. struct ol_object *
  140. make_collect_state_1(struct collect_info_1 *info,
  141.              struct ol_object *a);
  142.  
  143. struct ol_object *
  144. make_collect_state_2(struct collect_info_2 *info,
  145.              struct ol_object *a,
  146.              struct ol_object *b);
  147.  
  148. struct ol_object *
  149. make_collect_state_3(struct collect_info_3 *info,
  150.              struct ol_object *a,
  151.              struct ol_object *b,
  152.              struct ol_object *c);
  153.  
  154. #define STATIC_COLLECT_1(next) \
  155. { { { STATIC_HEADER, do_call_simple_command }, do_collect_1}, \
  156.   make_collect_state_1, next }
  157.  
  158. #define STATIC_COLLECT_2(next) \
  159. { STATIC_HEADER, make_collect_state_2, next }
  160.  
  161. #define STATIC_COLLECT_2_FINAL(f) \
  162. { STATIC_HEADER, f, NULL }
  163.  
  164. #define STATIC_COLLECT_3(next) \
  165. { STATIC_HEADER, make_collect_state_3, next }
  166.  
  167. #define STATIC_COLLECT_3_FINAL(f) \
  168. { STATIC_HEADER, f, NULL }
  169.  
  170. extern struct command_simple command_unimplemented;
  171. #define COMMAND_UNIMPLEMENTED (&command_unimplemented.super.super)
  172.  
  173. struct command command_die_on_null;
  174.  
  175. /* The CLASS_* macros are used by automatically generated evaluation code */
  176.  
  177. struct command_continuation *
  178. make_apply(struct command *f, struct command_continuation *c);  
  179. struct ol_object *gaba_apply(struct ol_object *f,
  180.                   struct ol_object *x);
  181.  
  182. #define CLASS_APPLY gaba_apply
  183.  
  184. extern struct command_simple command_I;
  185. #define CLASS_VALUE_I (&command_I.super.super)
  186. #define CLASS_APPLY_I_1(x) (x)
  187.  
  188. extern struct command_simple command_K;
  189. struct command *make_command_K_1(struct ol_object *x);
  190.  
  191. #define CLASS_VALUE_K (&command_K.super.super)
  192. #define CLASS_APPLY_K_1(x) ((struct ol_object *) make_command_K_1(x))
  193.  
  194. extern struct collect_info_1 command_S;
  195. /* extern struct collect_info_2 collect_info_S_2; */
  196.  
  197. struct command *make_command_S_2(struct command *f,
  198.                  struct command *g);
  199.  
  200. #define CLASS_VALUE_S (&command_S.super.super.super)
  201. #define CLASS_APPLY_S_1(f) (make_collect_state_1(&command_S, (f)))
  202. #define CLASS_APPLY_S_2(f, g) (collect_S_2(NULL, (f), (g)))
  203.  
  204. extern struct collect_info_1 command_Sp;
  205. extern struct collect_info_2 collect_info_Sp_2;
  206. /* extern struct collect_info_3 collect_info_Sp_3; */
  207.  
  208. struct command *make_command_Sp_3(struct command *c,
  209.                   struct command *f,
  210.                   struct command *g);
  211.  
  212. struct ol_object *collect_S_2(struct collect_info_2 *info,
  213.                    struct ol_object *f,
  214.                    struct ol_object *g);
  215. struct ol_object *collect_Sp_3(struct collect_info_3 *info,
  216.                 struct ol_object *c,
  217.                 struct ol_object *f,
  218.                 struct ol_object *g);
  219.  
  220. #define CLASS_VALUE_Sp (&command_Sp.super.super)
  221. #define CLASS_APPLY_Sp_1(c) (make_collect_state_1(&command_Sp, (c)))
  222. #define CLASS_APPLY_Sp_2(c, f) \
  223.   (make_collect_state_2(&collect_info_Sp_2, (c), (f)))
  224. #define CLASS_APPLY_Sp_3(c, f, g) (collect_Sp_3(NULL, (c), (f), (g)))
  225.  
  226. extern struct collect_info_1 command_B;
  227. /* extern struct collect_info_2 collect_info_B_2; */
  228.  
  229. struct command *make_command_B_2(struct command *f,
  230.                  struct command *g);
  231. struct ol_object *collect_B_2(struct collect_info_2 *info,
  232.                    struct ol_object *f,
  233.                    struct ol_object *g);
  234.  
  235. #define CLASS_VALUE_B (&command_B.super.super)
  236. #define CLASS_APPLY_B_1(f) (make_collect_state_1(&command_B, (f)))
  237. #define CLASS_APPLY_B_2(f, g) (collect_B_2(NULL, (f), (g)))
  238.  
  239. extern struct collect_info_1 command_Bp;
  240. extern struct collect_info_2 collect_info_Bp_2;
  241. extern struct collect_info_3 collect_info_Bp_3;
  242.  
  243. struct command *make_command_Bp_3(struct command *c,
  244.                   struct command *f,
  245.                   struct command *g);
  246. struct ol_object *collect_Bp_3(struct collect_info_3 *info,
  247.                 struct ol_object *c,
  248.                 struct ol_object *f,
  249.                 struct ol_object *g);
  250.  
  251. #define CLASS_VALUE_Bp (&command_Bp.super.super)
  252. #define CLASS_APPLY_Bp_1(c) (make_collect_state_1(&command_Bp, (c)))
  253. #define CLASS_APPLY_Bp_2(c, f) \
  254.   (make_collect_state_2(&collect_info_Bp_2, (c), (f)))
  255. #define CLASS_APPLY_Bp_3(c, f, g) (collect_Bp_3(NULL, (c), (f), (g)))
  256.  
  257. extern struct collect_info_1 command_C;
  258. /* extern struct collect_info_2 collect_info_C_2; */
  259.  
  260. struct command *
  261. make_command_C_2(struct command *f,
  262.          struct ol_object *y);
  263. struct ol_object *
  264. collect_C_2(struct collect_info_2 *info,
  265.         struct ol_object *f,
  266.         struct ol_object *y);
  267.  
  268. #define CLASS_VALUE_C (&command_C.super.super.super)
  269. #define CLASS_APPLY_C_1(f) (make_collect_state_1(&command_C, (f)))
  270. #define CLASS_APPLY_C_2(f, y) (collect_C_2(NULL, (f), (y)))
  271.  
  272. extern struct collect_info_1 command_Cp;
  273. extern struct collect_info_2 collect_info_Cp_2;
  274. /* extern struct collect_info_3 collect_info_Cp_3; */
  275.  
  276. struct command *
  277. make_command_Cp_3(struct command *c,
  278.           struct command *f,
  279.           struct ol_object *y);
  280. struct ol_object *
  281. collect_Cp_3(struct collect_info_3 *info,
  282.          struct ol_object *c,
  283.          struct ol_object *f,
  284.          struct ol_object *y);
  285.  
  286. #define CLASS_VALUE_Cp (&command_Cp.super.super)
  287. #define CLASS_APPLY_Cp_1(c) (make_collect_state_1(&command_Cp, (c)))
  288. #define CLASS_APPLY_Cp_2(c, f) \
  289.   (make_collect_state_2(&collect_info_Cp_2, (c), (f)))
  290. #define CLASS_APPLY_Cp_3(c, f, y) (collect_Cp_3(NULL, (c), (f), (y)))
  291.      
  292.  
  293. #endif
  294.